/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.view.customer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import src.services.customer.*;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */

@ManagedBean 
@SessionScoped
public class CustomerBean implements java.io.Serializable{
    /*private List<Idcard> availableIdCard;
    private List<Country> availableCountry;
    private List<Province> availableProvince;    
    private List<District> availableDistrict;
    private List<Subdistrict> availableSubdistrict;
    private List<Village> availableVillage;
    private List<Restatus> availableRestatus;    
    * 
    */
    
    private List<SelectItem> availableIdCard,availableCountry,availableProvince,availableDistrict,availableSubdistrict,availableVillage,availableRestatus;
    /*private List<Customer> customers;
    
    private Customer selectedData, insertedData;
    private boolean editMode;
    private String filter;
    CustomerModel helper;
*/
    public CustomerBean() {
  /*      helper = new CustomerModel();
        this.customers = helper.findAll(null);
        
        
    */    
        IdcardModel idc = new IdcardModel();
        this.availableIdCard = idc.listAll();
        RestatusModel rest = new RestatusModel();
        this.availableRestatus = rest.listAll();
        
        CountryModel ctry = new CountryModel();
        this.availableCountry = ctry.listAll();
      
        //performance reason jadi ditutup 
    /*    ProvinceModel prov = new ProvinceModel();
        this.availableProvince = prov.listAll();        
        DistrictModel dsc = new DistrictModel();
        this.availableDistrict = dsc.listAll();
        SubdistrictModel subdsc = new SubdistrictModel();
        this.availableSubdistrict = subdsc.listAll();
        VillageModel villa = new VillageModel();
        this.availableVillage = villa.listAll();
        * 
        */
        
        
    }

   
     public void handleCountryChange(Integer country) {  
         //&& !country.equals(-1)
        if(country !=null ) {
            Map<String, String> filters = new HashMap<>();       
            filters.put("tc.countryId", String.valueOf(country.intValue()));
            ProvinceModel prov = new ProvinceModel();
            this.availableProvince = prov.listAll(filters);  
        } 
            
    }  
     
     public void handleProvinceChange(Integer province) {  
        if(province !=null ) {
            Map<String, String> filters = new HashMap<>();       
            filters.put("tc.provinceId", String.valueOf(province.intValue()));
            DistrictModel district = new DistrictModel();
            this.availableDistrict = district.listAll(filters);  
        } 
            
    }  
     
     
     public void handleDistrictChange(Integer district) {  
        if(district !=null ) {
            Map<String, String> filters = new HashMap<>();       
            filters.put("tc.districtId", String.valueOf(district.intValue()));
            SubdistrictModel subdistrict = new SubdistrictModel();
            this.availableSubdistrict = subdistrict.listAll(filters);  
        } 
            
    }  
     
      public void handleSubdistrictChange(Integer subdistrict) {  
        if(subdistrict !=null && !subdistrict.equals(-1)) {
            Map<String, String> filters = new HashMap<>();       
            filters.put("tc.subdistrictId", String.valueOf(subdistrict.intValue()));
            VillageModel village = new VillageModel();
            this.availableVillage = village.listAll(filters);  
        } 
            
    }  

    
    public void countrySelected(Integer countryId) {
        FacesMessage msg = new FacesMessage();
        msg.setDetail("Kadieu");
//	msg.setSummary("Item Index: " + event.get());
//	msg.setDetail("Series Index:" + event.getSeriesIndex());
	FacesContext.getCurrentInstance().addMessage(null, msg);
        
       // Country selectedCountry = this.i
        
         /*Map<String, String> filters = new HashMap<>();       
        filters.put("countryId", String.valueOf(countryId));
       ProvinceModel prov = new ProvinceModel();
        this.availableProvince = prov.listAll(filters);        
        * 
        */
    }// end method

    
    public List<SelectItem> getAvailableIdCard() {
        return availableIdCard;
    }

    public List<SelectItem> getAvailableRestatus() {
        return availableRestatus;
    }

    public void setAvailableRestatus(List<SelectItem> availableRestatus) {
        this.availableRestatus = availableRestatus;
    }
    
    
    
    /*public boolean isEditMode() {
        return editMode;
    }

    

    public void setAvailableIdCard(List<Idcard> availableIdCard) {
        this.availableIdCard = availableIdCard;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }

    public String getFilter() {
        return filter;
    }

    public void setFilter(String filter) {
        this.filter = filter;
    }

    public CustomerModel getHelper() {
        return helper;
    }

    public void setHelper(CustomerModel helper) {
        this.helper = helper;
    }

    public Customer getInsertedData() {
        return insertedData;
    }

    public void setInsertedData(Customer insertedData) {
        this.insertedData = insertedData;
    }

    public Customer getSelectedData() {
        return selectedData;
    }

    public void setSelectedData(Customer selectedData) {
        this.selectedData = selectedData;
    }
    
    
    public void search() {
        Map<String, String> filters = new HashMap<String, String>();
      
        filters.put("subdistrictName", getFilter());
              
        this.customers = helper.findAll(filters);
        setFilter("");
    }
    
    
    */

    public List<SelectItem> getAvailableCountry() {
        return availableCountry;
    }

    public List<SelectItem> getAvailableDistrict() {
        return availableDistrict;
    }

    public List<SelectItem> getAvailableProvince() {
        return availableProvince;
    }

    public List<SelectItem> getAvailableSubdistrict() {
        return availableSubdistrict;
    }

    public List<SelectItem> getAvailableVillage() {
        return availableVillage;
    }

    public void setAvailableCountry(List<SelectItem> availableCountry) {
        this.availableCountry = availableCountry;
    }

    public void setAvailableDistrict(List<SelectItem> availableDistrict) {
        this.availableDistrict = availableDistrict;
    }

    public void setAvailableIdCard(List<SelectItem> availableIdCard) {
        this.availableIdCard = availableIdCard;
    }

    public void setAvailableProvince(List<SelectItem> availableProvince) {
        this.availableProvince = availableProvince;
    }

    public void setAvailableSubdistrict(List<SelectItem> availableSubdistrict) {
        this.availableSubdistrict = availableSubdistrict;
    }

    public void setAvailableVillage(List<SelectItem> availableVillage) {
        this.availableVillage = availableVillage;
    }
    
    
}
